package com.epfly.promo.activity.impl.discount.predicate;

import com.epfly.iface.promo.activity.enums.IsSuiteHolidayEnum;
import com.epfly.promo.activity.entity.ActivityEntity;
import com.epfly.promo.activity.feign.DataRestaurantFeignService;
import com.epfly.promo.activity.impl.discount.ActivityWrapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


/**
 * 活动节假日过滤
 */
@Order(value = PredicateOrder.IS_SUITE_HOLIDAY_ORDER)
@Service
public class IsSuiteHolidayPredicate implements ActivityDiscountPredicate {


    @Resource
    private DataRestaurantFeignService dataRestaurantFeignService;

    @Override
    public boolean test(ActivityWrapper activityWrapper) {

        ActivityEntity entity = activityWrapper.getActivityEntity();
        // 活动节假日设置为"不限"
        if (entity.getIsSuiteHoliday().equals(IsSuiteHolidayEnum.NO.getKey())) {
            return true;
        }

        // 活动节假日设置为"节假日不可用"，如果订单时间不落在节假日，才享受优惠活动。
        Long orderTime = activityWrapper.getOrderTime();
        String date = StringUtils.substring(String.valueOf(orderTime), 0, 8);

        boolean isHoliday = dataRestaurantFeignService.isHoliday(date);
        if (!isHoliday) {
            return true;
        }

        return false;
    }
}
